
package com.amado.springcloud.feignhystrix.controller;

import com.amado.springcloud.feignhystrix.client.UserFeignOne;
import com.amado.springcloud.user.entity.User;
import com.amado.springcloud.user.fegin.UserFeign;
import com.amado.springcloud.user.vo.SNSResult;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("one")
class HistryxOneControll {

	@Autowired
	private UserFeignOne userFeignOne;
	/**
	 * 断路器
	 * @return
	 */
	public SNSResult<User> getDefaultRole(){
		return new SNSResult<>(SNSResult.StatusCode.ERROR);
	}

	/**
	 * HystrixCommand当方法发生异常时返回 getDefaultRole方法
	 * @return
	 */
	@GetMapping
	@HystrixCommand(fallbackMethod = "getDefaultRole")
	public SNSResult<User> getUser() {
		return userFeignOne.getUser(1L);
	}
}
